<?php
function deleteGoal($goalid) {
	mysql_connect("localhost", "web964", "pass17") or die("Connection failed.");
	mysql_select_db("usr_web964_1") or die("Database does not exist.");
	
	$result = mysql_query("SELECT subgoaldeadline.fk_subgoalid AS fk_subgoalid
	 FROM subgoaldeadline, subgoal 
	 WHERE subgoal.fk_goalid = '$goalid'");
	 $subgoalid = "-1";
	while ($row = mysql_fetch_object($result)) {
		$subgoalid = $row->fk_subgoalid;
	}
	
	
	mysql_query("DELETE FROM subgoaldeadline WHERE fk_subgoalid = '$subgoalid'");
	mysql_query("DELETE FROM subgoal WHERE fk_goalid = '$goalid'");
	mysql_query("DELETE FROM goaldeadline WHERE fk_goalid = '$goalid'");
	mysql_query("DELETE FROM goal WHERE id = '$goalid'");
}
?>